# Maintainer: Jaroslav Lichtblau <svetlemodry@archlinux.org>
# Contributor: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Morten Linderud <foxboron@archlinux.org>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: eric <eric@archlinux.org>
# Contributor: Andrew Rose <ody@netrux.com>

pkgname=gif2png
pkgver=3.0.0
pkgrel=4
pkgdesc="A GIF to PNG image format converter"
arch=('loong64' 'x86_64')
url="http://www.catb.org/~esr/gif2png/"
license=('ZLIB')
depends=('glibc')
makedepends=('go' 'xmlto' 'docbook-xsl')
options=('!lto')
source=("https://gitlab.com/esr/gif2png/-/archive/$pkgver/gif2png-$pkgver.tar.gz" 'go.mod' 'go.sum')
sha512sums=('4f35995e89c2da65b538a88600f0f8f7b42ded8d7c41c8d11c46a7e8ad52d7bcb3a8cb497a96e18df40e7a53cd1fd0fd42b01a174400b54a8a8b3b79f533b2de'
            '2b7c190c89ce856b16c29337ad431de9c8e384864e7d7a2387ca3fa65d2d23e61856e352b3a5884d5d9b70e5372a63baaa284c2b6632cc882b7554da7b48d748'
            'fb8fef8a65388a11674f456904eafedc3107f3d10b24b9b7955382b47beb10d8314862537b5a18c2edbcd5a5f2d3e61ccd16b66cf21d327665b83d08c54a1bc7')
b2sums=('5e3a0e425ec1f18ef669b0ad0f7ac79235ded0fa9cbc8e215f53b8bcdb8a286c0b6b55005c804999843726a7884832c4e17bae574d9d326269bbbdae87279d28'
        '42c54423ce062a4bdcc38f7e7fc16412f5a40ee1ed5a0aaa3c121ea4adee0a3af073a7dcca01875305e6ba8447d950580a6b20f11d821a1391f962e0e77f3968'
        '788b7b466d86e77e5075296471b7f1fdd9b02ff6de351f78ff5a40116a62de364004d8d37a0b0f6119d8297455886943b99e2c8d106536651f5ed3249d2141fb')

prepare() {
  cd "$pkgname-$pkgver"

  # ensure reproducible builds with pinned dependencies
  cp ../go.{mod,sum} .

  # download dependencies
  go mod download
}

build() {
  cd "$pkgname-$pkgver"

  # set Go flags
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"

  go build -v \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-linkmode external -extldflags \"${LDFLAGS}\"" \
    .

  # man page
  xmlto man gif2png.xml
}

check() {
  cd "$pkgname-$pkgver"

  make -C test gif2png-test
}

package() {
  cd "$pkgname-$pkgver"

  # binary
  install -vDm755 -t "$pkgdir/usr/bin" gif2png

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/man/man1" gif2png.1

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" COPYING
}
